#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define LL long long
LL rd(){
    LL x=0,f=1;
    char c = getchar();
    while(c<'0'||c>'9'){
        if(c=='-') f=-1;
        c = getchar();
    }
    while(c>='0'&&c<='9'){
        x = (x<<3)+(x<<1)+(c^48);
        c = getchar();
    }
    return x*f;
}
const int N = 2e5+5;
const int M = 1e6+5;
LL a[N];
int n;
namespace sub1{
    const int N1 = 20005;
    LL f[2][N1];
    void solve(){
        memset(f,0,sizeof f);
        for(int i=1;i<=n;i++){
            int o = i&1;
            int p = o^1;
            memset(f[o],0,sizeof f[o]);
            f[o][0] = f[p][0] + (a[i-1]==a[i]?a[i]:0);
            for(int l=1;l<i;l++){
                f[o][l] = max(f[o][l],f[p][l]+(a[i-1]==a[i]?a[i]:0));
                f[o][i-1] = max(f[o][i-1],f[p][l]+(a[l]==a[i]?a[i]:0));
            }
        }
        LL res = 0;
        for(int i=0;i<n;i++) res = max(res,f[n&1][i]);
        cout<<res<<"\n";
    }
}
namespace sub2{
   const int N2 = 2e5+5;
    LL f[N2],mx[15];
    void solve(){

       int res = rand();
       cout<<res<<'\n';
    }
}
void solve(){
    n = rd();
    for(int i=1;i<=n;i++){
        a[i] = rd();
    }
    if(n<=20005) sub1::solve();
    else sub2::solve();
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T =rd();
    while(T--) solve();
    return 0;
}
